package com.example.wssapp;

import java.util.ArrayList;
import java.util.List;

import com.example.wssapp.adapter.CustomAdapter;
import com.example.wssapp.adapter.Item;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class EventActivity extends Activity {

	private EditText editText;
	private Button button;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event);
		editText = (EditText) findViewById(R.id.et1);
		button = (Button) findViewById(R.id.bt1);
		button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				String username = editText.getText().toString();
				if (null == username || "".equals(username)) {
					Toast.makeText(EventActivity.this,
							"Please enter your name", Toast.LENGTH_SHORT)
							.show();
				} else {
					Toast.makeText(EventActivity.this, "Hello, " + username,
							Toast.LENGTH_SHORT).show();
				}
			}
		});

		// ListView
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, new String[] { "java",
						"c", "c++", ".net" });
		ListView listView = (ListView) findViewById(R.id.lv);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				TextView tv = (TextView) view;
				String text = (String) tv.getText();
				Toast.makeText(EventActivity.this, text, Toast.LENGTH_SHORT)
						.show();
			}
		});

		// spinner
		ArrayAdapter<CharSequence> adapter2 = ArrayAdapter
				.createFromResource(this, R.array.day,
						android.R.layout.simple_selectable_list_item);
		Spinner spinner = (Spinner) findViewById(R.id.spinner);
		adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter2);

		// customAdapter
		Item item1 = new Item("张三", "三哥");
		Item item2 = new Item("李四", "四哥");
		List<Item> items = new ArrayList<Item>();
		items.add(item1);
		items.add(item2);
		CustomAdapter customAdapter = new CustomAdapter(this, items);
		ListView listView2 = (ListView) findViewById(R.id.lv2);
		listView2.setAdapter(customAdapter);
	}

}
